
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Mistral.Management;

namespace Mistral.SecureDrive.GUI
{
	public partial class DrivesForm : Form
	{
		Win32_DiskDrive[] _diskDrives;
		Win32_DiskDrive _selected;
		
		public DrivesForm()
		{
			InitializeComponent();
		}

		public Win32_DiskDrive[] Drives
		{
			set { _diskDrives = value; }
		}

		public Win32_DiskDrive Selected
		{
			get { return _selected; }
		}

		private void DrivesForm_Load( object sender, EventArgs e )
		{
			List<IListView> listViews = new List<IListView>( );
			foreach ( Win32_DiskDrive drive in _diskDrives )
			{
				listViews.Add( new ListView_Win32DiskDrive( drive ));
			}
			ListViewService.FillListView( _listView, listViews.ToArray( ) );
		}


		private void _listView_SelectedIndexChanged( object sender, EventArgs e )
		{
			if( _listView.SelectedIndices.Count == 1 )
			{
				_selected = _diskDrives[_listView.SelectedIndices[0]];
			}
		}

		private void _listView_MouseDoubleClick( object sender, MouseEventArgs e )
		{
			ListViewItem listViewItem = _listView.GetItemAt( e.X, e.Y );
			if( listViewItem != null )
			{
				_selected = ((ListView_Win32DiskDrive)listViewItem.Tag).Drive;
				
				DialogResult = DialogResult.OK;
				Close( );
			}
		}
	}
}